<template>
  <el-row type="flex" class="row-bg" justify="center">
    <!--    //最左边部分-->
    <el-col :xl="6" :lg="7">
      <h2>欢迎来到VueAdmin管理系统</h2>
      <el-image :src="require('@/assets/Ljyvx.jpg')" style="height: 200px; width: 200px"></el-image>
      <p>vx:ndbsm0123</p>
      <p>扫码加微信，哈哈哈哈哈</p>
    </el-col>
    <!--    //-->
    <!--    //中间分割线-->
    <el-col :span="1">
      <el-divider direction="vertical"></el-divider>
    </el-col>
    <!--    //-->
    <el-col :xl="6" :lg="7">
      <el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="100px" class="demo-loginForm">
        <!--        //那几个框框-->
        <el-form-item label="用户名" prop="username" style="width: 380px">
          <el-input v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password" style="width: 380px">
          <el-input v-model="loginForm.password"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="code" style="width: 380px">
          <!--          下面172px是验证码那个框框的宽度-->
          <el-input v-model="loginForm.code" style="width: 172px;float:left"></el-input>
          <el-image :src="captchaImg" class="captchaImg"></el-image>
        </el-form-item>
        <!--        //-->

        <!--        那两个按钮-->
        <el-form-item>
          <el-button type="primary" @click="submitForm('loginForm')">立即创建</el-button>
          <el-button @click="resetForm('loginForm')">重置</el-button>
        </el-form-item>
        <!--        //-->
      </el-form>
    </el-col>

  </el-row>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        username: '',
        password: '',
        code: '',
        token: ''
      },
      rules: {
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
        ],
        code: [
          {required: true, message: '请输入验证码', trigger: 'blur'},
          {min: 5, max: 5, message: '长度为 5 个字符', trigger: 'blur'}
        ],
      },
      captchaImg: null
    };
  },

  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$axios.post('/login', this.loginForm).then(res => {

          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    getCaptcha() {
      let _this = this;
      this.$axios.get('/captcha').then(res => {
        console.log('/captcha')
        console.log(res)
        _this.loginForm.token = res.data.data.token
        _this.captchaImg = res.data.data.captchaImg
      })
    }
    //Result - code、msg、data
  },
  created() {
    this.getCaptcha();
  }
}
</script>

<style scoped>
.el-row {
  background-color: #FAFAFA;
  height: 100%;
  /*下面两个是居中*/
  display: flex;
  align-items: center;
  /*文字居中*/
  text-align: center;
}

/*下面是中间分割线高度*/
.el-divider {
  height: 200px;
}

/*验证码那个图片向左偏移就是靠向输入验证码那个框框*/
.captchaImg {
  float: left;
  margin-left: 2px;
  /*使得验证码那个图片四个角更加圆滑*/
  border-radius: 4px;
}
</style>
